﻿@using Commonality.ReturnView
@using ModelToDto
@using Commonality
@model PagingData<RoleDTO>

@using (Html.BeginForm("Index", "Role", FormMethod.Get, new { @class = "row g-3" }))
{

    
    <p></p>
    <div class="row">
        <label class="col-sm-3 col-form-label">关键字</label>
        <div class="col-sm-3">
            @Html.TextBox("searchString", @Model.SearchString, new { @class = "form-control", @placeholder = "关键字" })
        </div>
        <div class="col-sm-2">
            <button type="submit" class="btn btn-primary mb-3">查询</button>
        </div>
        <div class="col-sm-3">
            <a href="/Role/Add">新增角色</a>
        </div>
    </div>
    <div class="mb-3 row" id="partialajaxlist" style="width:100%">
        <div class="div-table">
            @await Html.PartialAsync("ParRoleList", Model.DataList)
        </div>
        <Paging total="@Model.RecordCount"
                page-index="@Model.PageIndex"
                page-size="@Model.PageSize"
                route-url="/Role/Index"
                query="">
        </Paging>
    </div>
}

@section scripts {
    <script type="text/javascript">

        function ajaxDelete(id) {
            $.ajax({
                type: "Delete",
                url: '/Role/Delete',
                data: { id: id },
                success: function (data) {
                    if (data.success === true) {
                        $("#myConfirm").modal("hide");
                        location.reload(true);
                    }
                    else {
                        alert("删除失败了");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        }

        ///
        function confirm(fun, params, msg) {
            if ($("#myConfirm").length > 0) {
                $("#myConfirm").remove();
            }
            var html = "<div class='modal fade' id='myConfirm' >"
                + "<div class='modal-backdrop in' style='opacity:0; '></div>"
                + "<div class='modal-dialog' style='z-index:2901; margin-top:60px; width:400px; '>"
                + "<div class='modal-content'>"
                + "<div class='modal-header'  style='font-size:16px; '>"
                + "<span class='glyphicon glyphicon-envelope'>&nbsp;</span>信息！<button type='button' class='close' data-dismiss='modal'>"
                + "<span style='font-size:20px;  ' class='glyphicon glyphicon-remove'></span><tton></div>"
                + "<div class='modal-body text-center' id='myConfirmContent' style='font-size:18px; '>"
                + msg
                + "</div>"
                + "<div class='modal-footer ' style=''>"
                + "<button class='btn btn-danger ' id='confirmOk' >确定<tton>"
                + "<button class='btn btn-info ' id='cancel' data-dismiss='modal'>取消<tton>"
                + "</div>" + "</div></div></div>";
            $("body").append(html);

            $("#myConfirm").modal("show");

            $("#confirmOk").on("click", function () {
                $("#myConfirm").modal("hide");
                fun(params); // 执行函数
            });

            $("#cancel").on("click", function () {
                $("#myConfirm").modal("hide");
            });
        }

        function disable(id) {
            $.ajax({
                type: "Get",
                url: '/Role/Disable',
                data: { id: id },
                success: function (data) {
                    if (data.success === true) {
                        $("#myConfirm").modal("hide");
                        location.reload(true);
                    }
                    else {
                        alert("操作失败了");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        }


    </script>
}
